home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / indx18eu.zip / IWRITE.PAS < prev    next >
Pascal/Delphi Source File  |  1991-03-20  |  2KB  |  101 lines

  1. PROGRAM IWrite ;
  2.  
  3. USES
  4.        DOS ,
  5.        CRT ,
  6.        IndexedFiles ;
  7.  
  8. CONST
  9.        IndexedFileName                             = 'INDEXED' ;
  10.  
  11.  
  12. TYPE
  13.  
  14.        MyRec                                     = RECORD
  15.  
  16.          index                                   : IndexStr ;  {  From UNIT  }
  17.          name                                    : STRING ;
  18.          age                                     : BYTE ;
  19.          salary                                  : REAL ;
  20.          occurance                               : INTEGER ;
  21.          phone                                   : STRING ;
  22.  
  23.        END ;  {  MyRec  }
  24.  
  25. VAR
  26.        f                                         : IFile ;
  27.        temp                                      : MyRec ;
  28.        i                                         : INTEGER ;
  29.  
  30.  
  31.  FUNCTION    Index_Convert (     s               : STRING )
  32.                                                  : STRING ;
  33.  
  34.    BEGIN  {  Index_Convert  }
  35.  
  36.      WHILE ( Length ( s ) < 10 )
  37.       DO
  38.        BEGIN
  39.  
  40.          s := '0' + s ;
  41.  
  42.        END ;  {  WHILE  }
  43.  
  44.      Index_Convert := s ;
  45.  
  46.    END ;  {  Index_Convert  }
  47.  
  48.  FUNCTION StrNum (     n                         : LONGINT )
  49.                                                  : STRING ;
  50.  
  51.   VAR
  52.        s                                         : STRING ;
  53.  
  54.    BEGIN  {  StrNum  }
  55.  
  56.      Str ( n , s ) ;
  57.      StrNum := s ;
  58.  
  59.    END ;  {  StrNum  }
  60.  
  61.  
  62. BEGIN
  63.  
  64.   ClrScr ;
  65.  
  66.   AssignIndexed ( f , IndexedFileName ) ;
  67.   ReWriteIndexed ( f ) ;
  68.  
  69.     WITH temp
  70.      DO
  71.       BEGIN
  72.  
  73.         occurance := 0 ;
  74.         salary    := 250000.00 ;                        {  Dreaming *sigh*  }
  75.         age       := 25 ;
  76.         name      := 'Thomas E. Jenkins, Jr. ' ;
  77.         phone     := '(803) 788-7179' ;
  78.  
  79.         FOR i := 20 DOWNTO 2
  80.          DO
  81.           BEGIN
  82.  
  83.             index := Index_Convert ( StrNum ( i ) ) ;
  84.             WriteLn ( 'Inserting index [' , index , '].' ) ;
  85.             WriteIndexed ( f , temp , SizeOf ( MyRec ) ) ;
  86.  
  87.             IF ( fileError > 0 )
  88.              THEN
  89.                 WriteLn( 'FILE ERROR !! :  ' , IndexedError ( fileError ) ) ;
  90.  
  91.             Inc ( occurance ) ;
  92.             salary := salary + 10000 ;
  93.             Inc ( age , 3 ) ;
  94.  
  95.           END ;  {  FOR i  }
  96.  
  97.       END ;  {  WITH temp  }
  98.  
  99.   CloseIndexed ( f ) ;
  100.  
  101. END.